<?php

?>

<div class="hidden" id="vad-cont">
    <form class="well form-inline margin-horisontal login" action="" method="POST" name="vadForm" id="vadForm">
        <fieldset>

            <div class="control-group" id="cg-f_vad_view">
                <label class="control-label" for="f_vad_view">Отображение</label>
                <div class="controls">
                    <select id="vadViewId" name="f_vad_view" class="input-xlarge">
                    <?php
                        $views = selectViewableObjectsFromSet(getAllViews());
                        sortViewsByName($views);
                        $views[0] = array('id'=>0, 'obj_name'=>'Выберите отображение', 'obj_type'=>0);

                        $selvalue = Arr::getValue($params, 'view', 0);

                        foreach ($views as $row) {
                            $key = Arr::getValue($row, 'id', 0);
                            $val = Arr::getValue($row, 'obj_name', '???');

                            $sel = ($key == $selvalue)? 'selected="selected"' : '';
                            echo '<option value="'.$key.'" '.$sel.'>'.$val."</option>\n";
                        }
                    ?>
                    </select>
                </div>
                <span class="help-inline"></span>
            </div>
            
            <div class="control-group" id="cg-f_vad_date">
                <label class="control-label" for="f_vad_date">Дата</label>
                <div class="controls">
                    <input type="text" class="input-medium" id="vadDate" name="f_vad_date" value="<?php echo Arr::getValue($params, 'date', ''); ?>">
                    <button id="vadToday" class="btn btn-info" type="button"><i class="icon-calendar icon-white"></i> Сегодня </button>
                </div>
                <span class="help-inline"></span>
            </div>

            <div class="form-actions">
                <button class="btn btn-primary" id="vad-submit"><i class="icon-ok icon-white"></i> Показать</button>
                <button class="btn btn-danger" id="vad-cancel"><i class="icon-remove icon-white"></i> Отменить</button>
            </div>
        </fieldset>
    </form>
</div>


<script type="text/JavaScript" src="js/jquery.ui.datepicker-ru.min.js"></script>
<script>

    function vadDialogShow() {
        Elm.vadCont.dialog('open');
    }

    function vadDialogHide() {
        Elm.vadCont.dialog('close');
    }
    
    function vadDialogClose() {
        Elm.vadForm.submitCallback = function(data) {};
        Elm.vadForm.cancelCallback = function(data) {};
        vadDialogHide();
        return false;
    }
    
    
    function vadDialogOpen(params, onSubmit, onCancel) {
        params = $.extend({view: 0, date: ''},params);
        
        Elm.vadForm.submitCallback = onSubmit || function(){};
        Elm.vadForm.cancelCallback = onCancel || function(){};
        
        $('#vadViewId').val(params.view);
        $('#vadDate').val(params.date);
        vadDialogShow();
    }
    


    $(function() {
        Elm.vadCont = $('#vad-cont');
        Elm.vadForm = $('#vadForm');
        Elm.vadForm.submitCallback = function(data) {};
        Elm.vadForm.cancelCallback = function(data) {};
        Elm.vadDP = $('#vadDate');
        
        $.datepicker.setDefaults($.datepicker.regional['ru']);

        

        Elm.vadCont.dialog({
            width       : 350,
            modal       : true,
            resizable   : false,
            title       : "",
            autoOpen    : false,
            buttons     : {}
        }).removeClass('hidden');
        Elm.vadCont.dialog('widget').find('.ui-dialog-titlebar-close').hide();
        
        

        $('#vad-cancel').click(function(){
            if (typeof(Elm.vadForm.cancelCallback) == 'function') Elm.vadForm.cancelCallback();
            vadDialogClose();
            return false;
        });
        
        
        $('#vad-submit').click(function(){
            if (typeof(Elm.vadForm.submitCallback) == 'function') {
                var data = {
                    view: $('#vadViewId').val(),
                    date: $('#vadDate').val()
                };
                Elm.vadForm.submitCallback(data);
            }
            vadDialogClose();
            return false;
        });
        
        
        
    
        Elm.vadDP.datepicker({
            dateFormat  : "yy-mm-dd",
            currentText : "Сегодня",
            closeText   : "Закрыть",
            showButtonPanel: false,
            changeYear  : true,
            changeMonth : true
        });
        
        $('#vadToday').click(function(){Elm.vadDP.datepicker( "setDate" , '0' ); });


    });




</script>

<?php /*

Использование:  vadDialogOpen(params, onSubmit, onCancel);



*/ ?>
